import { defineStore } from "pinia"
import { computed, ref } from "vue"
import { UserInfo } from "@/model"
import { setUser } from "@/utils/storage"

export const useUserStore = defineStore('user', () => {
    const userInfo = ref<UserInfo | null>(null)
    
    const isLogin = computed(()=>{
        return userInfo.value !== null ? true:false;
    })

    function setUserInfo(value:UserInfo) {
        userInfo.value = value
        setUser(value)
    }

    return {
        userInfo,
        setUserInfo,
        isLogin
    }
})